#include"blockqueue.hpp"
#include<unistd.h>
using namespace Blockqueue;
int i = 0;
void* product(void* arg)
{
    blockqueue<int>* bq = (blockqueue<int>*)arg;
    while(1)
    {
        bq->product(i);
        std::cout<<"生成任务号：" << i <<std::endl;
        i++;
        sleep(1);
    }
}

void* consume(void* arg)
{
    blockqueue<int>* bq = (blockqueue<int>*)arg;
    int j;
    while(1)
    {
        bq->consume(&j);
        std::cout<<"消耗任务号：" << j <<std::endl;
        sleep(2);
    }

}

int main()
{
    pthread_t cth;
    pthread_t pth[2];
    blockqueue<int> bq(5);
    pthread_create(&pth[0],NULL,product,(void*)&bq);
    pthread_create(&pth[1],NULL,product,(void*)&bq);
    pthread_create(&cth,NULL,consume,(void*)&bq);
    pthread_join(pth[0],NULL);
    pthread_join(cth,NULL);
    return 0;
}